package hello.app.dialog;

import hello.app.HistoryActivity;
import hello.app.R;
import hello.app.model.data.HelloContact;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.telephony.PhoneNumberUtils;
import android.widget.Toast;

public class SelectHistorySubBuilder extends Builder implements OnClickListener{
	HelloContact mContact;
	HistoryActivity mActivity;
	int mPostion;
	static final int DETAIL = 0;
	static final int GOOGLE = 1;
	static final int OUTGOING = 2;
	static final int CONTACT = 3;

	public SelectHistorySubBuilder(HistoryActivity activity, HelloContact contact) {
		super(activity);
		this.mActivity = activity;
		this.mContact = contact;
		setItems(R.array.select_history, this);
	}

	public void onClick(DialogInterface dialog, int which) {
		Intent i;
		Uri uri;
		switch(which){
		case DETAIL:
			Toast.makeText(mActivity, mActivity.getString(R.string.trial_period_expiration), Toast.LENGTH_SHORT).show();
			break;
		case GOOGLE:
			uri = Uri.parse("http://google.co.jp/search?q=" + PhoneNumberUtils.formatNumber(mContact.getPhone()));
			i = new Intent(Intent.ACTION_VIEW,uri);
			mActivity.startActivity(i);
			break;
		case OUTGOING:
			uri = Uri.parse("tel:" + mContact.getPhone());
			i = new Intent(Intent.ACTION_CALL,uri);
			mActivity.startActivity(i);
			break;
		case CONTACT:
			Toast.makeText(mActivity, mActivity.getString(R.string.trial_period_expiration), Toast.LENGTH_SHORT).show();
	    	break;
		default:
			break;
		}
		dialog.cancel();
	}
}
